import React from 'react';
import TYPE from '@design/constant/component-type';
import {
  Select,
  DatePicker,
  TextArea,
  TextInput,
  Radio,
  Checkbox,
  Upload,
  QueryPicker,
} from './component';
import commands from './commands';
import schema from './schema';

export default function(options = {}) {
  const { injectProps } = options;
  return {
    renderBlock: (props, editor, next) => {
      const { type } = props.node;
      const newProps = injectProps(props);
      switch (type) {
        case TYPE.TEXT_INPUT:
          return <TextInput {...newProps} />;
        case TYPE.SELECT:
          return <Select {...newProps} />;
        case TYPE.TEXT_AREA:
          return <TextArea {...newProps} />;
        case TYPE.QUERYPICKER:
          return <QueryPicker {...newProps} />;
        case TYPE.DATEPICKER:
          return <DatePicker {...newProps} />;
        case TYPE.RADIO:
          return <Radio {...newProps} />;
        case TYPE.CHECKBOX:
          return <Checkbox {...newProps} />;
        case TYPE.UPLOAD:
          return <Upload {...newProps} />;
        default:
          return next();
      }
    },
    commands,
    schema,
  };
}
